### REPLICATION 
### Business Owners and Executives as Politicians: The Effect on Public Policy
### this script defines functions used in data cleaning & analysis


## formats numbers
format_num <- function(x, digits=3){
    x <- as.numeric(x)
    return(as.numeric(as.character(paste0(sprintf(paste0("%.", digits, "f"), x)))))
}



## capitalize string 
capitalize <- function(string) {
  substr(string, 1, 1) <- toupper(substr(string, 1, 1))
  string
}


# function to calculate weights for optimal bandwidth
weights_CCT <- function(run_var, h){
  (1 - abs(run_var/as.numeric(h))) * (abs(run_var) <= as.numeric(h))
}


# format plot axis scale
scale_fun <- function(x) paste0("$", sprintf("%.1f", x))

# format plot axis scale
scale_fun_revs <- function(x) paste0("  $", sprintf("%.1f", x))

